package com.example.mydemo928;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by Wang on 13-9-28.
 * 待命名空间的自定义的View
 */
public class LIViewWithSpaceName extends LinearLayout {
    String nameSpace="http://testNamespace";
    String labText;
    Bitmap bitmap;
    public LIViewWithSpaceName(Context context, AttributeSet attrs) {
        super(context, attrs);
        int resourseId=attrs.getAttributeResourceValue(nameSpace,"labText",0);
        if (0 == resourseId){
//            设置的值是直接存在于使用的地方 如   labText='我是文字'
            labText=attrs.getAttributeValue(nameSpace,"labText");
        }else {
            //设置的值是在 value的xml文件中
            labText=getResources().getString(resourseId);
        }
        if (labText == null){
            throw  new RuntimeException("必须设置labText 参数");
        }

        resourseId=attrs.getAttributeResourceValue(nameSpace, "ico", 0);
        Log.d("NEW","resourseId  "+resourseId);

        if (0 != resourseId){
            Log.d(this.getClass()+"","resourseId  "+resourseId);
            bitmap= BitmapFactory.decodeResource(getResources(),resourseId);
        }
        LayoutInflater inflater;
        inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout linearLayout= (LinearLayout) inflater.inflate(R.layout.layoutitem,this);
        TextView textView= (TextView) findViewById(R.id.textview1);
        ImageView imageView= (ImageView) findViewById(R.id.img);
        textView.setText(labText);
        if (null != bitmap){
            imageView.setImageBitmap(bitmap);
        }
    }

}
